<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite pt20 pb10 radius10 pl10 pr20 justify-between">
      <div>
        <el-input v-model="id" style="width: 280px" placeholder="搜尋ID..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-input v-model="uid" style="width: 280px" placeholder="搜尋用戶ID..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-input v-model="touid" style="width: 280px" placeholder="搜尋陪玩ID..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-input v-model="order_no" style="width: 280px" placeholder="搜尋訂單號..." :prefix-icon="Search" class="search mr10 mb10" />


      </div>
      <div class="noshrink mb10">
        <el-button class="btn2" @click="search()">查詢</el-button>
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell">
          <el-table-column prop="id" label="序號" width="80" />

          <el-table-column prop="uid" label="用戶訊息" width="200">
            <template #default="scope">
              <span @click="showUser(scope.row.user.id)">{{ scope.row.user.phone }}(ID:{{ scope.row.user.id }})</span>

            </template>
          </el-table-column>
          <el-table-column prop="touser" label="陪玩訊息" min-width="200">
            <template #default="scope">
              <span @click="showUser(scope.row.touser.id)">{{ scope.row.touser.phone }}(ID:{{ scope.row.touser.id }})</span>

            </template>
          </el-table-column>
          <el-table-column prop="address" label="下單地址" width="200" />
          <el-table-column prop="service_name" label="服務項目" width="150" />
          <el-table-column prop="order_no" label="訂單號" width="200" />
          <el-table-column prop="cancel_state_text" label="用戶取消狀態" width="200">
            <template #default="scope">
              <div><span class="yellow">{{ scope.row.cancel_state_text }}</span></div>

            </template>
          </el-table-column>
          <el-table-column prop="cancel_starttime" label="取消時間" width="200" />
          <el-table-column prop="cancel_result_text" label="審核結果" width="120">
            <template #default="scope">
              <div v-if="scope.row.cancel_result == 1"><span class="blue">同意退款</span></div>
              <div v-if="scope.row.cancel_result == 2"><span class="red">拒絕退款</span></div>
            </template>
          </el-table-column>
          <el-table-column prop="examine_name" label="審核人" width="120" />
          <el-table-column prop="cancel_endtime" label="審核時間" width="200" />
          <el-table-column prop="is_refund_text" label="退款狀態" width="120">
            <template #default="scope">
              <div v-if="scope.row.is_refund == 1"><span class="blue">已退款</span></div>
              <div v-if="scope.row.is_refund == 0"><span class="red">未退款</span></div>

            </template>
          </el-table-column>

          <el-table-column prop="" label="操作" width="80" fixed="right">
            <template #default="scope">
              <div class="align-center">
                <div class=" pointer" @click="edit(scope.row)">編輯</div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="plr20 mlauto mt20">
        <el-pagination v-model:current-page="currentPage" prev-text="上一頁" next-text="下一頁" :default-page-size="15" :small="small" :disabled="disabled" :background="true" layout="prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>

    </div>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { cancelList } from '@/api/order.js'
import { inject } from 'vue';
const showUser = inject('showUser');
onMounted(() => {
  getCancelList()
})

// 退款列表
const getCancelList = () => {
  cancelList({
    page: currentPage.value,
    id: id.value,
    uid: uid.value,
    touid: touid.value,
    order_no: order_no.value
  }).then((res) => {
    console.log('退款列表', res)
    tableData.value = res.data.data
    total.value = res.data.total
  })
}

const id = ref('')
const uid = ref('')
const touid = ref('')
const order_no = ref('')
const reset = () => {
  id.value = ''
  uid.value = ''
  touid.value = ''
  order_no.value = ''
  getCancelList()

}
const search = () => {
  getCancelList()
}


const dialogTableVisible = ref(false)
const dialogType = ref(1)
const dialogShow = (type) => {
  console.log('dialog----show----')
  dialogType.value = type
  dialogTableVisible.value = true
}

const tableData = ref([])
const currentPage = ref(1)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  getCancelList()
}
const router = useRouter()
const edit = (row) => {
  let data = {
    id: row.id,
    cancel_result: row.cancel_result,
    is_refund: row.is_refund,
    address: row.address,
    service_name: row.service_name
  }
  router.push({ path: 'editRefund', query: data })
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  // padding: 5px 0px;
}

:deep(.el-input__wrapper) {
  border: none;
}

:deep(.el-input__wrapper:hover) {
  border: none;
}
</style>
<style></style>
 